
$(function () {
    var job_datagrid = $("#job_datagrid");
    var experience_dialog = $("#experience_dialog");

    //tabs添加选项卡
    $('#job_tabs').tabs({
        fit:true,
        closable:true
    })
    //tabs添加选项卡
    $('#education_tabs').tabs({
        fit:true,
        //pill:true,
        //href:加载仅仅是html中body
        //href:node.url,
        //使用内嵌的方式
        //content:"<iframe width='98%'  height='98%'  src="+node.url+"></iframe>",
        closable:true
    })



    //开支表初始化（二维表）
    job_datagrid.datagrid({
        fit:true,
        url:"/experience/list",
        fitColumns:true,
        rownumbers:true,
        //分页
        pagination:true,
        pageList:[3,5,10],
        striped:true,
        singleSelect:true,
        fit:"true",

        columns:[[
           // {field:"ck",checkbox:true},  //显示多选框样式
            {field:"id", title:"编号", hidden:true},
            {field:"startTime", title:"开始时间", width:100},
            {field:"endTime", title:"结束时间", width:100},
            {field:"company", title:"单位", width:100},
            {field:"department", title:"部门", width:100},
            {field:"workContent", title:"工作内容", width:100},
            {field:"reasonForLeave", title:"离职原因", width:100},
        ]],
        toolbar:"#ccc",
    })



   /*
    var pp = $('#tt').tabs('getSelected');
    var tab = pp.panel('options').tab;*/
  /*  var bb = "/types";
    $("#tt").tabs({
        onSelect: function(title,index){
            if(index==1){
                var pp = $('#tt').tabs('getSelected');
                pp.tabs({
                    fit:true,
                    //pill:true,
                    //href:加载仅仅是html中body
                    //href:"/types",
                    //使用内嵌的方式

                   content:"<iframe width='98%'  height='98%'  src="+bb+"></iframe>",

                    closable:true
                })

            }
        }
    });
*/

    //编辑或更新对话框
    experience_dialog.dialog({
        width:480,
        height:280,
        buttons:"#experience_btn",
        closed:true
    })


    //响应函数集合对象
    var cmdObj = {
        reload: function (){
            job_datagrid.datagrid("load");
        },
        edit: function (){
            //alert("save");
            var row = job_datagrid.datagrid("getSelected");
            if(!row){
                $.messager.alert('温馨提示',"请选择要编辑的数据");
                return;
            }
            $("#experience_form").form("clear");

            $("#experience_form").form("load", row);
            experience_dialog.dialog("open");
            experience_dialog.dialog("setTitle", "工作经历编辑");
        },
        add:function (){
            $("#experience_form").form("clear");
            experience_dialog.dialog("open");
            experience_dialog.dialog("setTitle", "工作经历录入");

        },

        //保存操作
        save:function () {

            var id = $("#id").val();

            var url =  "/experience/save";
            if(id){
                url =  "/experience/update";
            }
            $("#experience_form").form('submit', {
                url: url,
                success: function (data) {
                    data = $.parseJSON(data);

                    if(!data.success){
                        $.messager.alert('温馨提示',data.msg);

                    }else{
                        experience_dialog.dialog("close");
                        job_datagrid.datagrid("load");
                    }
                }
            })
        },

        //删除操作
        remove:function () {

            var row = job_datagrid.datagrid("getSelected");

            if(!row){
                $.messager.alert('温馨提示',"请选择要删除的数据");
                return;
            }
            $.get("/experience/delete",{id:row.id}, function(data){

                if(data.success){
                    job_datagrid.datagrid("load");
                }else{
                    $.messager.alert('温馨提示',data.msg);
                }
            })

        },

        cancel:function (){
            experience_dialog.dialog("close");
        },
    }

    //调用
    $("a[data-cmd]").click(function(){
        var cmd = $(this).data("cmd");//eidt,remove,relod
        cmdObj[cmd]();
    })
    //调用
    $("a[data-job]").click(function(){
        var job = $(this).data("job");//eidt,remove,relod
        cmdObj[job]();
    })
});

